import openpyxl
# 官方文档
# https://openpyxl.readthedocs.io/en/stable/tutorial.html
def wirte():
    wb = openpyxl.Workbook()
    # 创建sheet
    # ws = wb.create_sheet('成绩单')
    # 激活
    ws = wb.active
    # 设置sheet标题
    ws.title = '成绩单'
    lst = [{'name': '姓名', 'chinese': '语文', 'math': '数学'},
           {'name': '张三', 'chinese': 99, 'math': 80},
           {'name': 'lisi', 'chinese': 89, 'math': 99}
           ]
    for i, item in enumerate(lst, start=1):
        ws[f'A{i}'] = item.get('name')
        ws[f'B{i}'] = item.get('chinese')
        ws[f'c{i}'] = item.get('math')
    #保存
    wb.save('./a.xlsx')

def read():
    # 加载一个工作簿
    wb = openpyxl.load_workbook('./a.xlsx')
    print(wb.sheetnames)
    # 获取工作表sheet
    ws = wb.get_sheet_by_name('成绩单')
    print(dir(ws))
    for i in range(1, ws.max_row+1):
        print(ws[f'A{i}'].value)
        print(ws[f'B{i}'].value)

if __name__ == '__main__':
    # wirte()
    read()